#include "Log.h"
#include "Json.h"
#include "JsonTest.h"


JsonTest::JsonTest(void)
{
}


JsonTest::~JsonTest(void)
{
}

bool JsonTest::Test()
{
	printf("=================JsonTest=================\n");
	Json::Value jValue;
	jValue["a"] = 1;
	jValue["b"] = 2.1;
	jValue["c"] = "3";
	jValue["d"].append(Json::Value(1));
	jValue["d"].append(Json::Value(2));
	jValue["d"].append(Json::Value(3));
	jValue["e"]["a"] = 1;
	jValue["e"]["b"] = 2.1;
	jValue["e"]["c"] = "3";
	Json::FastWriter jWriter;
	std::string str = jWriter.write(jValue);
	printf("jValue:%s\n", str.c_str());
	jValue.clear();
	str = jWriter.write(jValue);
	printf("jValue:%s\n", str.c_str());

	FILE* pFile = fopen("Config/test.json", "r");
	if ( pFile )
	{
		char buff[10240]="";
		size_t i = 0;
		for ( ; i < 10240; i++ )
		{
			int character = fgetc(pFile);
			if ( character == EOF )
				break;
			buff[i] = character;
		}
		buff[i] = '\0';

		Json::Reader jReader;
		jReader.parse(buff,buff+i,jValue);

		str = jWriter.write(jValue);
		printf("jValue:%s\n", str.c_str());
	}
	
	printf("=================JsonTest=================\n\n");
	return true;
}
